package com.taocore.top.title.action;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import jxl.read.biff.BiffException;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.taocore.top.title.service.RealTimeKeywordsImport;
import com.taocore.top.title.service.WeeklyKeywordsService;
import com.taocore.top.title.servlet.MainServlet;

@Results({
	@Result(name="success", type="httpheader")
})
public class ImportAction extends ActionBase{

	static Logger _log = Logger.getLogger(ImportAction.class.getName());
	
	public String execute()
	{
		String root = MainServlet.getRootPath();
		String path = root + "WEB-INF/data/week.xls";
		_log.info("path: " + path);
		long t0 = System.currentTimeMillis();
		try {
			_log.info("go...........");
//			WeeklyKeywordsImport.importData(path);
			_log.info("weekly keywords imported.");
			RealTimeKeywordsImport.importData();
			_log.info("real time keywords imported.");
		} 
//		catch (BiffException e) {
//			_log.log(Level.SEVERE, "", e);
//		} 
		catch (IOException e) {
			_log.log(Level.SEVERE, "", e);
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "", e);
		}
		long t1 = System.currentTimeMillis();
		_log.info("import data cost: " + (t1 - t0));
		return SUCCESS;
	}
}
